/**
 * Created by yumeng on 2017/11/17.
 */
define([
  './themes/lang/' + window.YUFP_SYS_CONFIG.language + '/pages/example/template/exampleGroup.js'
], function (require, exports) {
  exports.ready = function (hashCode, data, cite) {
    yufp.lookup.reg('GENDER,EDUCATION_TYPE,IDENT_TYPE');
    var vm = yufp.custom.vue({
      el: '#exampleGroup',
      data: function () {
        var _this = this;
        return {
          expandCollapseName: ['base'],
          // 未分组表单数据格式
          baseFields: [{
            columnCount: 2,
            fields: [
              { field: 'name', label: this.$t('exampleGroup.xm') },
              { field: 'gender', label: this.$t('exampleGroup.xb'), type: 'select', dataCode: 'GENDER' },
              { field: 'education', label: this.$t('exampleGroup.xl'), type: 'select', dataCode: 'EDUCATION_TYPE' },
              { field: 'cardType', label: this.$t('exampleGroup.zjlx'), type: 'select', dataCode: 'IDENT_TYPE' },
              { field: 'barthday', label: this.$t('exampleGroup.csrq'), type: 'date' },
              { field: 'cardNo', label: this.$t('exampleGroup.zjhm') },
              { field: 'company', label: this.$t('exampleGroup.gs') },
              { field: 'email', label: this.$t('exampleGroup.yx') }
            ]
          }],
          familyFields: [{
            columnCount: 2,
            fields: [
              { field: 'peopleNum',
                label: this.$t('exampleGroup.cys'),
                rules: [
                  {required: true, message: this.$t('exampleGroup.btx'), trigger: 'blur' },
                  { validator: yufp.validator.number}
                ] },
              { field: 'home', label: this.$t('exampleGroup.fwqk')},
              { field: 'address', label: this.$t('exampleGroup.jtdz') },
              { field: 'postcode', label: this.$t('exampleGroup.yzbm')}
            ]
          }],
          otherFields: [{
            columnCount: 1,
            fields: [
              { field: 'desc', label: this.$t('exampleGroup.bz'), type: 'textarea'}
            ]
          }],
          // 分组表单数据格式
          // totalFields:[
          //     {
          //             title: '基本信息',
          //             name: 'base',
          //             columnCount: 2,
          //             fields: [
          //                 { field: 'name', label: this.$t('exampleGroup.xm') },
          //                 { field: 'gender', label: this.$t('exampleGroup.xb'), type: 'select', dataCode: 'GENDER' },
          //                 { field: 'education', label: this.$t('exampleGroup.xl'), type: 'select', dataCode: 'EDUCATION_TYPE' },
          //                 { field: 'cardType', label: this.$t('exampleGroup.zjlx'), type: 'select', dataCode: 'IDENT_TYPE' },
          //                 { field: 'barthday',label: this.$t('exampleGroup.csrq'),type: 'date' },
          //                 { field: 'cardNo', label: this.$t('exampleGroup.zjhm') },
          //                 { field: 'company', label: this.$t('exampleGroup.gs') },
          //                 { field: 'email', label: this.$t('exampleGroup.yx') }
          //             ]
          //     },
          //     {
          //             title: '家庭信息',
          //             name: 'family',
          //             columnCount: 2,
          //             fields: [
          //                 { field: 'peopleNum', label: this.$t('exampleGroup.cys'), rules: [
          //                     {required: true, message: this.$t('exampleGroup.btx'), trigger: 'blur' },
          //                     { validator: yufp.validator.number}
          //                 ] },
          //                 { field: 'home', label: this.$t('exampleGroup.fwqk')},
          //                 { field: 'address', label: this.$t('exampleGroup.jtdz') },
          //                 { field: 'postcode', label: this.$t('exampleGroup.yzbm')}
          //             ]
          //     },
          //     {
          //             title: '其他信息',
          //             name: 'other',
          //             columnCount: 1,
          //             fields: [
          //                 { field: 'desc', label: this.$t('exampleGroup.bz'), type: 'textarea'}
          //             ]
          //     }
          // ],
          baseRules: {
            name: [
              {required: true, message: this.$t('exampleGroup.btx'), trigger: 'blur' }
            ],
            gender: [
              { required: true, message: this.$t('exampleGroup.btx'), trigger: 'change'}
            ],
            education: [
              { required: true, message: this.$t('exampleGroup.btx'), trigger: 'change' }
            ],
            email: [
              { type: 'email', message: this.$t('exampleGroup.qsrzqdyxdz'), trigger: 'blur' }
            ],
            barthday: [
              { type: 'date', required: true, message: this.$t('exampleGroup.btx'), trigger: 'change' }
            ],
            cardType: [
              {required: true, message: this.$t('exampleGroup.btx'), trigger: 'change' }
            ]
          }
        };
      },
      methods: {
        submitForm: function () {
          var me = this;
          var base = me.$refs.baseRef, family = me.$refs.familyRef, other = me.$refs.otherRef;
          var baseFlag = true;
          var familyFlag = true;
          var otherFlag = true;
          base.validate(function (valid) {
            baseFlag = valid;
          });
          family.validate(function (valid) {
            familyFlag = valid;
          });
          other.validate(function (valid) {
            otherFlag = valid;
          });
          if (baseFlag && familyFlag && otherFlag) {
            var comitData = {};
            yufp.extend(comitData, base.formModel);
            yufp.extend(comitData, family.formModel);
            yufp.extend(comitData, other.formModel);
            this.$msgbox.alert(comitData, this.$t('exampleGroup.ts'));
          }
        },
        resetForm: function () {
          this.$refs.baseRef.resetFields();
          this.$refs.familyRef.resetFields();
          this.$refs.otherRef.resetFields();
        }
      }
    });
  };
});
